<template>
    <div id="myCard">
        <header class="header">选择推荐人</header>
        <section class="receiveitems">
            <scroller snappingHeight="10" class="scroller" :on-refresh="refresh" :on-infinite="infinite" ref="my_scroller">
                <div class="receiveitem" v-for="(item,index) in userLists" :class="{active:dataid==item.icarduid}" :key="index" @click="choose(item.icarduid)">
                    <i><img :src="baseUrl.baseUrl+item.cplogo"></i>
                    <p>{{decodeURIComponent(item.cname)}}</p>
                </div>
            </scroller>
        </section>
        <footer @click="submit(dataid)">确认推荐</footer>
    </div>
</template>

<script>
import {followList,recommendCard} from '../../../js/dataServe.js'
import {baseUrl} from '../../../config/env'
export default {
    data(){
        return {
            inputval:'',
            userLists:[],
            baseUrl:{baseUrl},
            dataid:'',
            pageNo:1,
            uidArr:[]
        }
    },
    components:{},
    created(){
        // this.$store.commit('changeShowit',{val:false})
    },
    mounted(){
       
    },
    methods:{
        infinite(done) {

            if(sessionStorage.sid){
                let self = this;
                let responseData = followList(self.pageNo,self.inputval);
                responseData.then((res)=>{
                                        // alert(decodeURIComponent(res.msg))
                                        if(res.data.list && res.data.list.length>0){
                                           
                                            let items = res.data.list;
                                            // console.log(items)
                                            items.forEach( (item,key) => {
                                                if(self.uidArr.indexOf(item.ifocusuid)==-1){
                                                    self.uidArr.push(item.ifocusuid)
                                                    self.userLists.push(item)
                                                }
                                            })
                                            self.pageNo++;
                                            done();
                                            
                                        }else{
                                            self.$refs.my_scroller.finishInfinite(2);
                                        }
                                    })
            }
        },
        refresh(done) {
            done()
        },
        choose(id){
            this.dataid = id;//控制背景的高亮状态
        },
        submit(id){
            if(!id){
                alert('请选择推荐给谁')
            }else if(sessionStorage.sid){
                let self = this;
                let responseData = recommendCard(self.$route.query.icardid,id);
                responseData.then((res)=>{
                                            // alert(decodeURIComponent(res.msg))
                                            if(res.result==200 || res.result==1){
                                                self.$message({
                                                    duration: 2000,
                                                    message: '推荐成功',
                                                    type: 'success'
                                                })
                                            }else{
                                                self.$message({
                                                    duration: 2000,
                                                    message: res.msg,
                                                    type: 'error'
                                                })
                                            }
                                        })
            }
        }
    }
}
</script>

<style scoped >
#myCard {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    width: 100%;
    height:100%;
    position: absolute;
    top: 0;
    left: 0;
}
.header{
    width:100%;
    height:3rem;
    line-height:3rem;
    background:#2790A6;
    color:#ffffff;
    font-size:1.2rem;
    position: fixed;
    top: 0;
    z-index:5;
}
section{
    position: absolute;
    width: 100%;
    height: auto;
    top: 3rem;
    bottom: 3rem;
}
.receiveitem{
    display:flex;
    padding:0.5rem 1rem;
    border-bottom: 1px solid #dfdfdf;
}
.receiveitem i{
    width:4rem;
    height:4rem;
    display:block;
}
.receiveitem p{
    height:4rem;
    line-height:4rem;
    margin-left:1rem;
}
.receiveitem i img{
    width:100%;
    height:100%;
    border-radius:5rem;
}
footer{
    position: fixed;
    bottom: 0;
    width: 100%;
    color: #ffffff;
    height: 3rem;
    line-height: 3rem;
    background: #606266;
}
.active{
    background: rgba(0,0,0,0.3);
}
</style>
